package views;

/**
 * EDCHomeViewer 
 * Viewer for EDCTableModel
 */

import java.awt.Dimension;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.TableColumnModel;
//import javax.swing.table.TableRowSorter;

import ui.EDCTableModel;
import utils.EDCResource;

public class EDCHomeViewer extends EDCDefaultViewer {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
//	private static EDCHomeViewer current;
	private EDCTableModel tModel;
	private JTextField filterText;
	private JTextField statusText;
	private JTable table;
//	private TableRowSorter<EDCTableModel> sorter;

	protected String[] columnToolTips = {
			"bla1",
			"bla2",
			"bla3",
	"bla4"};

	public EDCHomeViewer() {
		tModel = new EDCTableModel();
		setTitle("Home viewer");

//		System.out.println("dtdFolderName: "+dtdPath);
//		tModel.setData(dtdPath);
		
		tModel.setData(EDCResource.URL_CATALOG_PATH);

		table = new JTable(tModel);
		
//		sorter = new TableRowSorter<EDCTableModel>(tModel);
//		table.setRowSorter(sorter);
//		table.setFillsViewportHeight(true);
		
		table.setPreferredScrollableViewportSize(new Dimension(650,600));

		//Columns size
		setColumnWidth(table,0,160);
		setColumnWidth(table,1,250);
		setColumnWidth(table,2,120);
		setColumnWidth(table,3,100);

//		tModel.setTableHeader(table.getTableHeader());

		//Create the scroll pane and add the table to it.
		JScrollPane jsp = new JScrollPane(table);

		//Add the scroll pane to this JInternalFrame.
		getContentPane().add(jsp);
		showHorScroll(table, true);
	}

	/**This method shows the horizontal scroll bar when required.
	 * It's being called in the constructors.
	 */
	public void showHorScroll(JTable t, boolean show) {
		if (show){
			t.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		}else{
			t.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
		}
	}

	/**this method should be called to set the column
	 *at pColumn index to a width of pWidth
	 */
	public void setColumnWidth(JTable t, int pColumn, int pWidth){
		//get the column model
		TableColumnModel colModel = t.getColumnModel();
		//get the column at index pColumn, and set its preferred width
		colModel.getColumn(pColumn).setPreferredWidth(pWidth);
	}

	public JTable getTable(){
		return table;
	}

	public EDCTableModel getEDCTableModel(){
		return tModel;
	}

}